package com.wang.qiniuyun.controller;

import com.qiniu.storage.DownloadUrl;
import com.qiniu.util.Auth;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * @author: wang
 * @date: 2021/7/30 18:33
 * @description:
 */
@Controller
public class FileDownLoadController {


    @RequestMapping("/download")
    public String download(@RequestParam("path") String path) throws UnsupportedEncodingException {
//        DownloadUrl url = new DownloadUrl("http://qx1u4e0ll.hn-bkt.clouddn.com", false, "Fh3aMSz8JRUUzm10lqtcfPwgURUo");
//        url.setAttname(path);
        String domainOfBucket = "http://qx1u4e0ll.hn-bkt.clouddn.com";
        String encodedFileName = URLEncoder.encode(path, "utf-8").replace("+", "%20");
        String finalUrl = String.format("%s/%s", domainOfBucket, encodedFileName);
        System.out.println(finalUrl);
        return "test";
    }
}
